﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using Bilylib;
using System.Data;

public partial class FAQ : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindAnswer();
        }
    }

    private void BindAnswer()
    {
        try
        {
            DataTable tbFAQ = new DataTable();
            string sql = "Select FullName, Title, Email, Question, Answer, CONVERT(VARCHAR(10), DateQuestion, 101) AS DateQuestion, QuestionStatus, Status From FAQ Where QuestionStatus = @QuestionStatus And Status = @Status";
            Select select = Select.newInstance();
            select.SetConnectionName("HoangThinhDataConnectionString");
            select.SetValues(1);
            select.SetValues(1);
            tbFAQ = select.SelectCustomParam(sql);
            pager.DataSource = tbFAQ.DefaultView;
            pager.BindToControl = dtlFAQ;
            dtlFAQ.DataSource = pager.DataSourcePaged;
            dtlFAQ.DataBind();
        }
        catch { }
    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {
            string date = DateTime.Now.ToString("MM/dd/yyyy");
            string sql = "Insert Into FAQ Values(@Name, @Title, @Email, @Question, @Answer, @Date, @QuestStatus, @Status);";
            Insert insert = Insert.newInstance();
            insert.SetConnectionName("HoangThinhDataConnectionString");
            insert.SetParamValues(txtName.Text.Replace("'", ""));
            insert.SetParamValues(txtTittle.Text.Replace("'", ""));
            insert.SetParamValues(txtEmail.Text.Replace("'", ""));
            insert.SetParamValues(txtQuestion.Text.Replace("'", ""));
            insert.SetParamValues("");
            insert.SetParamValues(date);
            insert.SetParamValues(0);
            insert.SetParamValues(1);
            
            if (insert.InsertCustomParam(sql))
            {

                lblMsg.ForeColor = ColorTranslator.FromHtml("#009900");
                lblMsg.Text = "Gửi câu hỏi thành công";
                txtName.Text = "";
                txtTittle.Text = "";
                txtEmail.Text = "";
                txtQuestion.Text = "";
            }
            else
            {
                lblMsg.ForeColor = ColorTranslator.FromHtml("Red");
                lblMsg.Text = "Gửi câu hỏi thất bại !!";
            }
        }
        catch {
            lblMsg.ForeColor = ColorTranslator.FromHtml("Red");
            lblMsg.Text = "Gửi câu hỏi thất bại !!";
        }
    }
}